package com.sunnada.btfvilg.controller;

import com.sunnada.btfvilg.common.response.Result;
import com.sunnada.btfvilg.common.response.ResultFactory;
import com.sunnada.btfvilg.entity.Deliveryman;
import com.sunnada.btfvilg.entity.User;
import com.sunnada.btfvilg.model.request.DelimanParamVo;
import com.sunnada.btfvilg.model.request.UserRegParamVo;
import com.sunnada.btfvilg.model.response.AddrVo;
import com.sunnada.btfvilg.model.response.DelimanListVo;
import com.sunnada.btfvilg.model.response.UserListVo;
import com.sunnada.btfvilg.model.response.UserVo;
import com.sunnada.btfvilg.service.DeliverymanService;
import com.sunnada.btfvilg.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 快递员相关的接口
 */
@RestController
@RequestMapping("Deliman")
@Api(tags = "快递员")
public class DelimanController {

    @Autowired
    private DeliverymanService deliverymanService;

    @PostMapping("/addDeliman")
    @ApiOperation(value = "新增快递员", httpMethod = "POST")
    public Result<UserVo> addDeliman(@Validated @RequestBody DelimanParamVo delimanVo) {
        UserVo userVo = deliverymanService.addDeliman(delimanVo);
        return ResultFactory.success("添加成功",userVo);
    }

    @GetMapping("/delDeliman")
    @ApiOperation(value = "删除快递员", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "did", value = "快递员id", dataType = "String", paramType = "query", required = true)
    })
    public Result<Object> delDeliman(String did) {
        deliverymanService.delDeliman(did);
        return ResultFactory.success("删除成功", null);
    }


    @PostMapping("/updateDeliman")
    @ApiOperation(value = "修改快递员信息", httpMethod = "POST")
    public Result<Object> updateDeliman(@Validated @RequestBody DelimanParamVo delimanVo) {
        deliverymanService.updateDeliman(delimanVo);
        return ResultFactory.success("修改成功",null);
    }

    @GetMapping("/getDelimanList")
    @ApiOperation(value = "根据网点id获取快递员列表", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sid", value = "网点id，没有该项则获取全部快递员", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "numPerPage", value = "每页记录数", dataType = "String", paramType = "query", required = true)
    })
    public Result<DelimanListVo> getDelimanList(String sid, Integer page, Integer numPerPage) {
        DelimanListVo delimanList = deliverymanService.getDelimanList(sid, page, numPerPage);
        return ResultFactory.success(delimanList);
    }

    @GetMapping("/getDelimanById")
    @ApiOperation(value = "通过快递员id获取快递员信息", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "did", value = "快递员id", dataType = "String", paramType = "query", required = true)
    })
    public Result<Deliveryman> getDelimanById(String did) {
        Deliveryman deliman = deliverymanService.getDelimanById(did);
        return ResultFactory.success(deliman);
    }

}
